package org.halo.trade.data.config;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import redis.clients.jedis.HostAndPort;

public class Config
{
	public static final int REDIS_PORT = 60002;
	public static final String REDIS_HOSTS = "127.0.0.1";
	// 请把修改config类中的新浪用户名和口令。
	static public String sina_user = "13810224909";
	static public String sina_pwd = "wuhua330";

	// 如果你需要uuyun识别验证码，请到优优云申请用户名和口令：
	static public String uuy_user = "13810224909";
	static public String uuy_pwd = "wuhua330";
	
	public static Set<HostAndPort> getJedisCluster (){
		Set<HostAndPort> jedisSet = new HashSet<HostAndPort>();
		jedisSet.add(new HostAndPort("127.0.0.1",60002));
		jedisSet.add(new HostAndPort("127.0.0.1",60003));
		jedisSet.add(new HostAndPort("127.0.0.1",60004));
		jedisSet.add(new HostAndPort("127.0.0.1",60005));
		return jedisSet;
	}
	
	  //设定查询的字符串，拼接
		public static String makeLevel2QueryString(List<String> symbols, List<String> Indexsymbols,int fetchtype)
		{
			String list = "";
			if (symbols != null)
			{
				for (String symbol : symbols)
				{
					list +=  (Config.makeLevelQueryStr(symbol,fetchtype)+",");
				}
			}
			if (Indexsymbols != null)
			{
				for (String symbol : Indexsymbols)
				{
					list +=  (Config.makeIndexQueryStr(symbol)+",");
				}
			}
			if(list.endsWith(",")){
				list = list.substring(0,list.length()-1);
			}
			return list;
		}

		
	public static String makeLevelQueryStr(String symbol,int featchtype)
	{
		String str = "";
		String daimas = generateCode(symbol);
		if(featchtype  ==0){
			str = "2cn_" + daimas + "";
		}
		if(featchtype  ==1){
			str = "2cn_" + daimas + "_0" + ",2cn_" + daimas + "_1";
		}
		if(featchtype  ==2){
			str = "2cn_" + daimas + ",2cn_" + daimas + "_0" + ",2cn_" + daimas + "_1";
		}
		if(featchtype  ==3){
			str = "2cn_" + daimas + "_i";
		}
		if(featchtype  ==4){
			str = "2cn_" + daimas + ",2cn_" + daimas + "_orders" + ",2cn_" + daimas + "_0" + ",2cn_" + daimas + "_1";
		}
		//str = "2cn_" + daimas + ",2cn_" + daimas + "_orders" + ",2cn_" + daimas + "_0" + ",2cn_" + daimas + "_1";
		return str;
	}

	public static String makeIndexQueryStr(String symbol)
	{
		String str = "";
		String daimas = generateCode(symbol);
		str = "2cn_" + daimas;
		return str;
	}
	
	public static String generateCode(String id)
	{
		if (id == null || id.equals(""))
			return "";

		String code = "";
		String flag = "sh";

		// String list =
		// "sh000001_zdp,sz399001_zdp,sz399300_zdp,sz399005_zdp,sz399102_zdp";

		if (id.startsWith("50"))// 基金
		{
			flag = "sh";
		} else if (id.startsWith("160") || id.startsWith("150"))// 基金
		{
			flag = "sz";
		} else if (id.equals("000001") || id.equals("000300"))// 2cn_sh000001=上证指数,//
		// 沪深300
		{
			flag = "sh";
		} else if (id.startsWith("399"))// //深证成指,中小板指,创业板指
		{
			flag = "sz";
		} else if (id.startsWith("600") || id.startsWith("60"))
		{
			flag = "sh";
		} else if (id.startsWith("002") || id.startsWith("00"))
		{
			flag = "sz";
		} else if (id.startsWith("300"))
		{
			flag = "sz";
		} else
		{
			flag = "sz";
		}
		code += flag + id;
		return code;
	}
	

	public static List<List> loadConfigFile(int stocklength,int splitCount) {
		// 组织list
		List<List> allsymbols = new ArrayList<List>();
		// 从文件里读取arglength 的数据
		File file = new File("symbols.txt");
		if (file.exists()) {
			try {
				int line = 1;
				List<String> _symbols = new ArrayList<>();
				String tempString = "";
				BufferedReader input = new BufferedReader(new FileReader(file));
				while ((tempString = input.readLine()) != null) {
					_symbols.add(tempString);
					// 显示行号
					if (line++ >= stocklength) {
						allsymbols.add(_symbols);
						if (allsymbols.size() >= splitCount) {
							break;
						}
						_symbols = new ArrayList<>();
						line = 0;
					}

				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return allsymbols;
	}

}
